<template>
    <div class="">
        <h4 class="margin_bottom20">列表</h4>
        <el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="12">
                <el-button type="primary" size="small" data-id="3" @click="e_userstart(1)">
                    <i class="iconfont icon-qiyong"></i>会员启用</el-button>
                <el-button type="primary" size="small" data-id="2" @click="e_userstart(0)">
                    <i class="iconfont icon-jinyong"></i>会员禁用</el-button>
                <el-button type="primary" size="small" data-id="4" @click="e_repeatPwd">
                    <i class="iconfont icon-web-icon-"></i>重置登录密码</el-button>
            </el-col>
            <el-col :span="6">
                <el-input placeholder="关键字..." size="small" v-model="searchKey">
                    <el-button slot="append" icon="search" @click="loadData"></el-button>
                </el-input>
            </el-col>
        </el-row>
        <template>
            <el-table :data="tableData" border style="width: 100%; text-align: center;margin-top:10px;" v-loading.body="loading" @selection-change="handleSelectionChange">
                <el-table-column type="index" style="width:50%"></el-table-column>
                <el-table-column type="selection"></el-table-column>
                <el-table-column prop="accountName" header-align="center" label="登录名"></el-table-column>
                <el-table-column prop="accountType" header-align="center" label="会员类型">
                    <template slot-scope="scope">
                        <span v-text="checkMemberType(scope.row.accountType)"></span>
                    </template>
                </el-table-column>
                <!--<el-table-column prop="isExamineRealNameAuthentication" header-align="center" label="审核实名认证">-->
                    <!--<template slot-scope="scope">-->
                        <!--<span v-text="checkISReal(scope.row.isExamineRealNameAuthentication)"></span>-->
                    <!--</template>-->
                <!--</el-table-column>-->
                <!--<el-table-column prop="isSubmitRealNameAuthentication" header-align="center" label="提交实名认证">-->
                    <!--<template slot-scope="scope">-->
                        <!--<span v-text="checkSubReal(scope.row.isSubmitRealNameAuthentication)"></span>-->
                    <!--</template>-->
                <!--</el-table-column>-->
                <el-table-column prop="regType" header-align="center" label="注册类型">
                    <template slot-scope="scope">
                        <span v-text="checkRegType(scope.row.regType)"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="isActive" header-align="center" label="是否启用">
                    <template slot-scope="scope">
                        <span v-text="checkIsActive(scope.row.isActive)"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="fisTelephoneBind" header-align="center" label="是否绑定手机号">
                    <template slot-scope="scope">
                        <span v-text="checkfisPhone(scope.row.fisTelephoneBind)"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="realName" header-align="center" label="真实姓名"></el-table-column>
                <el-table-column prop="logonMode" header-align="center" label="登录方式" :show-overflow-tooltip="true">
                     <template slot-scope="scope">
                        <span v-text="checkLoginType(scope.row.logonMode)"></span>
                    </template>
                </el-table-column>
                <el-table-column prop="time" header-align="center" label="创建时间" :show-overflow-tooltip="true"></el-table-column>

            </el-table>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10,20,40]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </template>
    </div>
</template>
<script>
var qs = require('qs')
import Editor from '../../components/editor.vue'
import { tokenGet, TokenUrl, tokenPost } from '../../api/token.js'
export default {
	data() {
		return {
			checked: true,
			tableData: [],
			currentPage: 1,
			radio: {
				radioC: '1', //是否可以充值
				radioT: '1', //是否可以提现
				radioD: '1', //充值是否到账
				radioB: '1', //虚拟币类型
				radioY: '1', //是否以太坊
				radioZ: '1', //状态
			},
			typeNumber: [],
			total: 0,
			limit: 10,
			searchKey: '',
			loading: false,
			jinyong: [], //禁用id
		}
	},
	methods: {
		handleSizeChange(val) {
			console.log(val)
			this.limit = val
			this.loadData()
		},
		handleCurrentChange(val) {
			console.log(val)
			this.currentPage = val
			this.loadData()
		},
		handleSelectionChange(val) {
			this.typeNumber = val
			this.jinyong = val
			console.log(this.typeNumber)
		},
        /**
         * @Description: ${获取表格数据}
         * @Param
         * @Return
         * @Author 焦政
         * @Date 2018/11/14
         * @Version 1.0
         */
		 loadData() {
		    this.loading = true;
			 tokenPost(TokenUrl.userInfo, {offset: this.limit*(this.currentPage - 1), limit: this.limit, searchKey: this.searchKey}).then((response) => {
		        console.log(response)
		        this.tableData = response.data.data.rows;
		        this.total = response.data.data.total;
		        this.loading = false;
		    }, (response) => {

		    });
		},
		//会员类型判断
		checkMemberType(s) {
			if (s == 0) {
				return '普通会员'
			} else if (s == 1) {
				return '销售商'
			} else if (s == 2) {
				return '生产商'
			}
		},
		// 是否通过实名
		checkISReal(i) {
			if (i == 0) {
				return '否'
			} else if (i == 1) {
				return '是'
			} else if (i == -1) {
				return '未通过'
			}
		},
		// 是否提交过实名
		checkSubReal(i) {
			if (i == 0) {
				return '否'
			} else if (i == 1) {
				return '是'
			}
		},
		// 注册类型
		checkRegType(t) {
			if (t == 0) {
				return '后台添加'
			} else if (t == 1) {
				return '手机注册'
			}
		},
		// 是否绑定过手机
		checkfisPhone(i) {
			if (i == 0) {
				return '否'
			} else if (i == 1) {
				return '是'
			}
        },
        // 登录方式
        checkLoginType(t){
            if (t == 0) {
				return '前台'
			} else if (t == 1) {
				return '后台'
			}
        },
		checkIsActive(a){
		 	if(a == 0){
		 		return '否'
            }else if (a == 1){
		 		return '是'
            }
        },
		// ============================================表格数据状态类型判断👆==============================================//
	    /**
	     * @Description: ${会员启用}
	     * @Param
	     * @Return
	     * @Author 焦政
	     * @Date 2018/11/14
	     * @Version 1.0
	     */
		e_userstart(s){
            if(this.jinyong.length == 0){
				this.$alert('请选择一个用户进行操作')
                return
            }
            if(this.jinyong.length > 1){
				this.$alert('只能一次选择一位用户进行启用')
                return
            }
            let startParams = {
				userId:this.jinyong[0].id,
				status:s
            }
			tokenPost(TokenUrl.userStart,startParams).then(re=>{
                if(re.status == 200){
					this.loadData()
                }else{
                }
            })
        },
        /**
         * @Description: ${重置密码}
         * @Param
         * @Return
         * @Author 焦政
         * @Date 2018/11/14
         * @Version 1.0
         */
		e_repeatPwd(){
			if(this.jinyong.length == 0){
				this.$alert('请选择一个用户进行操作')
				return
			}
			if(this.jinyong.length > 1){
				this.$alert('只能一次选择一位用户进行重置密码')
				return
			}
			let reseatParams={
				userId:this.jinyong[0].id
            }
            tokenPost(TokenUrl.reseatPwd,reseatParams).then(re=>{
				if(re.data.status == 0){
					this.$alert(`${re.data.msg}  默认密码123456`)
                }else{
					this.$alert(re.data.msg)
                }
            })
        },
    },

	//引入文本编辑器那个组件
	components: {
		'v-editor': Editor,
	},
	created() {
		this.loadData()
	},
}
</script>
<style>
.el-dialog--small {
	width: 60%;
}
</style>
